package hl7;

//Imports
import com.orion.symphonia3.MessageFactory;
import com.orion.symphonia3.MessageElement;
import com.orion.symphonia3.MessageComponent;
import java.io.IOException;

public class EDC_HL7InputParser {

	//Declaration
	private MessageFactory m_factory;
	
	//Constructor
	public EDC_HL7InputParser() {
		try {
			m_factory = new MessageFactory();
			m_factory.loadDefinition("hl7.pcf");
		}
		catch(IOException ioe) {
			ioe.printStackTrace();
		}
	}

	//Methods
	public MessageComponent parse(String flatwire) {
		MessageElement m_elem;
		m_elem = m_factory.parse(flatwire);

		if (m_elem.getName().equals("ACK"))
			return new EDC_HL7MsgACK(m_elem);

		else if (m_elem.getName().equals("ORFR04"))
			return new EDC_HL7MsgORFR04(m_elem);

		else if (m_elem.getName().equals("ORFW02"))
			return new EDC_HL7MsgORFW02(m_elem);

		else if (m_elem.getName().equals("QCKQ02"))
			return new EDC_HL7MsgQCKQ02(m_elem);

		else if (m_elem.getName().equals("QRYR02"))
			return new EDC_HL7MsgQRYR02(m_elem);

		else if (m_elem.getName().equals("QRYT12"))
			return new EDC_HL7MsgQRYT12(m_elem);


		return null;	//Returns null if message type does not exist
	}

	//Method to create EDC_HL7MsgACK message
	public EDC_HL7MsgACK createEDC_HL7MsgACK() {
		EDC_HL7MsgACK msg = new EDC_HL7MsgACK(m_factory.createMessage("ACK"));
		return msg;
	}
	//Method to create EDC_HL7MsgORFR04 message
	public EDC_HL7MsgORFR04 createEDC_HL7MsgORFR04() {
		EDC_HL7MsgORFR04 msg = new EDC_HL7MsgORFR04(m_factory.createMessage("ORFR04"));
		return msg;
	}
	//Method to create EDC_HL7MsgORFW02 message
	public EDC_HL7MsgORFW02 createEDC_HL7MsgORFW02() {
		EDC_HL7MsgORFW02 msg = new EDC_HL7MsgORFW02(m_factory.createMessage("ORFW02"));
		return msg;
	}
	//Method to create EDC_HL7MsgQCKQ02 message
	public EDC_HL7MsgQCKQ02 createEDC_HL7MsgQCKQ02() {
		EDC_HL7MsgQCKQ02 msg = new EDC_HL7MsgQCKQ02(m_factory.createMessage("QCKQ02"));
		return msg;
	}
	//Method to create EDC_HL7MsgQRYR02 message
	public EDC_HL7MsgQRYR02 createEDC_HL7MsgQRYR02() {
		EDC_HL7MsgQRYR02 msg = new EDC_HL7MsgQRYR02(m_factory.createMessage("QRYR02"));
		return msg;
	}
	//Method to create EDC_HL7MsgQRYT12 message
	public EDC_HL7MsgQRYT12 createEDC_HL7MsgQRYT12() {
		EDC_HL7MsgQRYT12 msg = new EDC_HL7MsgQRYT12(m_factory.createMessage("QRYT12"));
		return msg;
	}

}
